/*
* Copyright (C) 2012 Manuel Pérez
*
* This file is part of OpenSudoku.
*
* OpenSudoku is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenSudoku is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenSudoku. If not, see <http://www.gnu.org/licenses/>.
*
*/
package modeloa;

import java.awt.Dimension;
import java.sql.SQLException;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import dBasea.Kontsultak;

public class BezeroModeloa extends AbstractTableModel {

	private static final long serialVersionUID = -1376327497825787062L;

	String[] columnNames = { "NAN", "Izena", "Abizenak", "Helbidea",
			"Telefonoa", "Asegurua" };
	List<Bezero> bezeroak;
	int x;
	String i;
	Kontsultak konts = new Kontsultak();

	public void init() {
		try {
			bezeroak = konts.listatuBezeroak();
		} catch (SQLException e) {

			e.printStackTrace();
		}
	}

	public void init2(int x, String i) {
		try {
			bezeroak = konts.bilatuBezeroak(x, i);
		} catch (SQLException ex) {

			ex.printStackTrace();
		}

	}

	public int getColumnCount() {
		return columnNames.length;
	}

	public int getRowCount() {
		return bezeroak.size();
	}

	public String getColumnName(int col) {
		return columnNames[col];
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		switch (columnIndex) {
		case 0:
			return bezeroak.get(rowIndex).getNAN();
		case 1:
			return bezeroak.get(rowIndex).getIzena();
		case 2:
			return bezeroak.get(rowIndex).getAbizenak();
		case 3:
			return bezeroak.get(rowIndex).getHelbidea();
		case 4:
			return bezeroak.get(rowIndex).getTelefonoa();
		case 5:
			return bezeroak.get(rowIndex).getAseguruTipoa();

		default:
			return null;
		}
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Class getColumnClass(int c) {
		return getValueAt(0, c).getClass();
	}

	public boolean isCellEditable(int row, int col) {
		return false;
	}

	/*
	 * public void setValueAt(Object value, int row, int col) { data[row][col] =
	 * value; fireTableCellUpdated(row, col); }
	 */
	public Bezero getFila(int index) {
		return bezeroak.get(index);
	}

	public void setPreferredScrollableViewportSize(Dimension dimension) {
		this.setPreferredScrollableViewportSize(dimension);
	}

}
